*WHAT'S ACROSS THE BORDER?
*JHA, NEUMARK, AND RODRIGUEZ-LOPEZ

include directories.do

* Load data at the czone-state-industry level
use "`datadir'`s'cbp_county_state_20ind_sample.dta", clear

*Remove DC (starts in 2004)
drop if czone==11304 & state==11

*Keep restaurant industry
keep if wagerank90==1

* Generating variables 

gen mw=max_mw
gen lmw=log(mw)

*Generate totempm, which removes emp of the industry of interest
foreach b in "emp" {
gen tot`b'm=tot`b'-`b'
}

foreach b in "emp" "wageap" {

gen l`b'=log(`b')
gen ltot`b'=log(tot`b')
gen ltot`b'm=log(tot`b'm)
}

gen lworkagepop=log(workagepop)

**Generate YEAR DUMMIES 
qui tab year, gen(yeard)

 *Dummies region-year
qui tab region, gen(regiond)
gen regionyear=region*10000+year
qui tab regionyear, gen(regionyeard)

*State dummies
qui tab state, gen(stated)
gen trend=year-1989
forvalues z = 1/48 {
gen statedtrend`z'=stated`z'*trend
}

**************generating conditions and controls*************
local window1 "year<=2016"

* Specify clustering

local options "vce(cluster state)"


* Specify outcome/regressor/instrument
local xvar "lmw"

* Specify controls
local year_controls yeard*
local regionyear_controls regionyeard*
local statetrend_controls statedtrend*

ren cty_fips county
merge m:1 county using "`countydir'`s'countytypes.dta"
drop _merge

/* Regression specs */

foreach d in "emp" "wageap" {

local yvar "l`d'"
local county_controls "ltot`d'm lworkagepop"


eststo m`d': reghdfe  `yvar' `xvar' `county_controls'  if  (`window1') , `options' absorb(county year)
eststo n`d': reghdfe  `yvar' `xvar' `county_controls'  if  (`window1') & type0==1 , `options' absorb(county year)

}

/* Print results */

tempfile specs

#delimit ;
esttab memp* nemp* using "`specs'.csv",
	nodepvars
	collabels(, none)
	mlabels(, none)
	b(%9.3f) se(%9.3f)
	star(* .10 ** .05 *** .01)
	title("Conventional TWFE county level -- emp")
	keep(`xvar' ltotempm lworkagepop)
	nonotes
	label
	stats(N, labels("N") fmt(0))	
	replace;
#delimit cr

#delimit ;
esttab mwage* nwage* using "`specs'.csv",
	nodepvars
	collabels(, none)
	mlabels(, none)
	b(%9.3f) se(%9.3f)
	star(* .10 ** .05 *** .01)
	title("Conventional TWFE county level -- earnings")
	keep(`xvar' ltotwageapm lworkagepop)
	nonotes
	label
	stats(N, labels("N") fmt(0))	
	append;
#delimit cr

* Switch the output to Excel format
insheet using "`specs'.csv", comma clear
export excel "`outdir'`s'TablesJNR.xlsx", sheetreplace sheet(TableA5)








